/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package viewer.common;

/**
 *
 * @author Steve Noble
 */
import java.awt.Point;

public class Trans2D {

    public static class Vec2D {
        public final double x;
        public final double y;
        public Vec2D( double xIn, double yIn) {
            x = xIn;
            y = yIn;
        }
    }

    // new origin
    public final double x;
    public final double y;
    public final double xScale;
    public final double yScale;

    public Trans2D() {
        x = 0;
        y = 0;
        xScale = 1;
        yScale = 1;
    }

    public Trans2D(double xIn, double yIn, double scaleIn) {
        x = xIn;
        y = yIn;

        if (scaleIn < 1.e-12) {
            scaleIn = 1;
        }
        
        xScale = scaleIn;
        yScale = scaleIn;
    }

     public Trans2D(double xIn, double yIn, double xScaleIn, double yScaleIn) {
        x = xIn;
        y = yIn;

        if (xScaleIn < 1.e-12) {
            xScaleIn = 1;
        }

        if (yScaleIn < 1.e-12) {
            yScaleIn = 1;
        }

        xScale = xScaleIn;
        yScale = yScaleIn;
    }

    public Point map(Vec2D v) {
        double rValX = xScale * (v.x - x);
        double rValY = yScale * (v.y - y);

        return new Point( (int) rValX, (int) rValY);
    }

     public Vec2D invMap( Point p) {
        double rValX = (p.x/xScale) + x;
        double rValY = (p.y/yScale) + y;

        return new Vec2D(rValX, rValY);
    }
}
